// 随机数
function selectFrom(lowerVal, upperVal) {  // lowerVal:最小值, upperVal:最大值
  //取值范围总数
  var choices = upperVal - lowerVal + 1;
  return Math.floor(Math.random() * choices + lowerVal);
}

// 返回随机抽取的题目id
function chooseProblems(levelScope, init) {  // levelScope：抽取范围；init：抽取数量
  let selectedProblemsId = [];
  for(let i=0; i<init; i++){
    // 1.levelScope中随机取1个值
    let num = selectFrom(0, levelScope.length);
    //console.log('num'+num);
    // 2.在levelScope中内取id
    let numId = levelScope[num];
    //console.log('numId'+numId);
    // 3.在levelScope中把numId删除
    levelScope.splice(num, 1);
    //console.log('levelScope'+levelScope);
    // 4.把numId存入selectedProblemsId
    selectedProblemsId.push(numId);
    //console.log('selectedProblemsId'+selectedProblemsId);
  }
  return { a: selectedProblemsId, b: levelScope};
}

module.exports = {
  selectFrom: selectFrom,
  chooseProblems: chooseProblems
}